﻿using System;
using System.Reflection;
using System.Windows;

namespace JTG.AutoDevice.Factory
{
    /// <summary>
    /// 自动创建窗口工厂，用于不同医院不同配置
    /// </summary>
    public class WindowFactory
    {
       
        public Window CreatePrintService(string funcName)
        {
            //加载程序集
            var assembly = Assembly.Load("JTG.AutoDevice");

            foreach (var t in assembly.GetTypes())
            {
                var customAttributes = t.GetCustomAttributes(typeof(ServiceInterface.Attribute.FunctionName), true);
                if (customAttributes.Length <= 0) continue;

                //查找方法
                foreach (var attribute in ((ServiceInterface.Attribute.FunctionName[])customAttributes))
                {
                    if (!attribute.FcName.ToString().Equals(funcName)) continue;

                    if (t.FullName == null) return null;
                    var type = assembly.GetType(t.FullName);
                    return (Window)Activator.CreateInstance(type);
                }
            }

            return null;
        }
    }
}
